﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;

namespace ERP_RORZE.Product.MonthlyCharge
{
    public partial class frm_MonthlyExpenceEdit : DevExpress.XtraEditors.XtraForm
    {
        public event EventHandler Reload;
        DataTable dt;
        ClsBasicListDAO clsBasicDAO = new ClsBasicListDAO();
        MonthlyExpence b = new MonthlyExpence();
        ClsMonthlyExpenceDAO clsMonthlyExpenceDAO = new ClsMonthlyExpenceDAO();

        public string ExpenceID;
        public string YearMonth;
        public string Amount;
        public string Description;

        public frm_MonthlyExpenceEdit()
        {
            InitializeComponent();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frm_MonthlyExpenceEdit_Load(object sender, EventArgs e)
        {
            dt = clsBasicDAO.GetAllExpence();
            cbExpenceID.DataSource = dt;
            cbExpenceID.DisplayMember = "ExpenceID";
            cbExpenceID.ValueMember = "ExpenceID";

            //
            cbExpenceID.Text = ExpenceID;
            dateYearMonth.Value = DateTime.Parse(YearMonth);
            txtAmount.Text = Amount;
            txtDescription.Text = Description;
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (txtAmount.Text == "")
            {
                MessageBox.Show("Amount không được để trống");
            }
            else
            {
                try
                {
                    decimal.Parse(txtAmount.Text);
                    b.ExpenceID = cbExpenceID.Text;
                    b.Amount = Decimal.Parse(txtAmount.Text);
                    b.YearMonth = dateYearMonth.Value;
                    clsMonthlyExpenceDAO.UpdateMonthlyExpence(b);
                    Reload(sender, e);
                }
                catch
                {
                    MessageBox.Show("Amount phải là kiểu money");
                }
            }
        }
    }
}